<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="昵称、备注" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DFBD')" type="primary" @click="DFBDHandle()" :disabled="dataListSelections.length <= 0">订房绑定</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DFJB')" type="danger" @click="DFJBHandle()" :disabled="dataListSelections.length <= 0">订房解绑</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DCBD')" type="primary" @click="DCBDHandle()" :disabled="dataListSelections.length <= 0">点餐绑定</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DCJB')" type="danger" @click="DCJBHandle()" :disabled="dataListSelections.length <= 0">点餐解绑</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DPBD')" type="primary" @click="DPBDHandle()" :disabled="dataListSelections.length <= 0">点评绑定</el-button>
        <el-button v-if="isAuth('wxuserinfo:wxuserbind:DPJB')" type="danger" @click="DPJBHandle()" :disabled="dataListSelections.length <= 0">点评解绑</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        v-if="false"
        prop="id"
        header-align="center"
        align="center"
        label="id">
      </el-table-column>
      <el-table-column
        prop="headimgurl"
        header-align="center"
        align="center"
        label="头像">
        <template slot-scope="scope">
          <img  :src="scope.row.headimgurl" alt="" style="width: 50px;height: 50px">
        </template>
      </el-table-column>
      <el-table-column
        prop="nickname"
        header-align="center"
        align="center"
        label="昵称">
      </el-table-column>
      <el-table-column
        prop="sex"
        header-align="center"
        align="center"
        label="性别"
      :formatter="showFormat">
      </el-table-column>
      <el-table-column
        prop="province"
        header-align="center"
        align="center"
        label="所在省份">
      </el-table-column>
      <el-table-column
        prop="city"
        header-align="center"
        align="center"
        label="所在城市">
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="备注">
      </el-table-column>
      <el-table-column
        prop="isdfnotice"
        header-align="center"
        align="center"
        label="订房通知">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isdfnotice === 0" size="small" type="danger">否</el-tag>
          <el-tag v-if="scope.row.isdfnotice === 1" size="small" >是</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isdcnotice"
        header-align="center"
        align="center"
        label="点餐通知">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isdcnotice === 0" size="small" type="danger">否</el-tag>
          <el-tag v-if="scope.row.isdcnotice === 1" size="small" >是</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isdpnotice"
        header-align="center"
        align="center"
        label="点评通知">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isdpnotice === 0" size="small" type="danger">否</el-tag>
          <el-tag v-if="scope.row.isdpnotice === 1" size="small" >是</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/wxuserinfo/wxuserbind/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 订房绑定
      DFBDHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行订房消息绑定操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DFBD'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 订房解绑
      DFJBHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行订房消息解绑操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DFJB'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 点餐绑定
      DCBDHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行点餐消息绑定操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DCBD'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 点餐解绑
      DCJBHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行点餐消息解绑操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DCJB'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 点评绑定
      DPBDHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行点评消息绑定操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DPBD'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 点评解绑
      DPJBHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对勾选用户进行点评消息解绑操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/wxuserinfo/wxuserbind/DPJB'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 解析性别
      showFormat (row, column) {
        if (row.sex === 1) {
          return '男'
        } else if (row.sex === 2) {
          return '女'
        } else {
          return ''
        }
      }
    }
  }
</script>
